! Roel Matthysen
! s0202264
! Finale versie Project Deel 1

program test

use methods
use IO
implicit none
integer, parameter :: doubleprecision = kind(0.d0)
integer i,n
logical :: verbose = .true.
real(doubleprecision),allocatable :: A(:,:),B(:,:)
real(doubleprecision) :: errortaylor, erroreig, erroreigqr
CHARACTER(len = 27) :: fnamein
CHARACTER(len = 28) :: fnameout

print *, '########################'
print *, '#### TEST PROGRAMMA ####'
print *, '########################'
print *, ' '
print *, 'Test 1-3: voorbeelden uit de opgave'
print *, 'Test 4-6: willekeurige symmetrische matrices'
print *, '          van grootte 4x4,16x16,32x32'
print *, 'Test 7-9: willekeurige asymmetrische matrices'
print *, '          van grootte 4x4,16x16,32x32'
print *, ' '
print *, 'Fout per testmatrix voor de drie algoritmes:'
print *, ' '
write(6,'(18x,a14,2x,a14,2x,a14)') 'taylor        ','eig           ','eigqr         '
print *, '------------------------------------------------------------'
! Debugging informatie afzetten
verbose = .false.
do i = 1,9
	! Input en output regelen
	WRITE(fnamein,'(a,i1,a)')'testmatrices/testmatrix', i, '.in'
  	OPEN(32,file=fnamein)
	WRITE(fnameout,'(a,i1,a)') 'testmatrices/testmatrix', i, '.out'
	OPEN(33,file=fnameout)	
	n = readsize(32)
	! Data alloceren
	allocate(A(n,n))
	allocate(B(n,n))
	A = readmatrix(32)
	B = readmatrix(33)
	! Fouten berekenen
	errortaylor = compare(B,taylorexp(A,verbose))
	erroreig = compare(B, eig(A,verbose))
	erroreigqr = compare(B, eigqr(A,verbose))
	write(6, '(a4,3x,i1,7x,es14.7,2x,es14.7,2x,es14.7)') 'Test', i, errortaylor, erroreig, erroreigqr
	deallocate(A)
	deallocate(B)
enddo

contains

function compare(A,B) result(error)
real(doubleprecision) :: error
real(doubleprecision) :: A(:,:),B(:,:)
error = maxval(abs(A-B))
end function

end program
